﻿using System;
using System.Threading.Tasks;

namespace QPEngine
{
    public class EnterRoomHandler
    {
        public class PeopleEnterRoom
        {
            public static async Task<bool> Enter(Session session,long account)
            {
                //向大厅请求用户信息
                StartConfig dbStartConfig = Game.Scene.GetComponent<StartConfigComponent>().DBConfig;
                string dbAddress = dbStartConfig.GetComponent<InnerConfig>().Address;
                Session InnerSession = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
                HallPlayerResponse response = await InnerSession.Call<HallPlayerResponse>(new HallPlayerRequest { account = account });

                Player player = response.p;
                player.session = session;
                if (session.GetComponent<SessionPlayerComponent>() == null) { session.AddComponent<SessionPlayerComponent>(); }
                session.GetComponent<SessionPlayerComponent>().Player = player;
                //调用玩家进入房间接口
                return ObjectEvents.Instance.PeopleEnter(player);
            }
        }

        [MessageHandler(AppType.Game1)]
        public class Game1EnterRequestHandler : AMRpcHandler<Game1EnterRequest, Game1EnterResponse>
        {
            protected override async void Run(Session session, Game1EnterRequest message, Action<Game1EnterResponse> reply)
            {
                Game1EnterResponse response = new Game1EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game2)]
        public class Game2EnterRequestHandler : AMRpcHandler<Game2EnterRequest, Game2EnterResponse>
        {
            protected override async void Run(Session session, Game2EnterRequest message, Action<Game2EnterResponse> reply)
            {
                Game2EnterResponse response = new Game2EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game3)]
        public class Game3EnterRequestHandler : AMRpcHandler<Game3EnterRequest, Game3EnterResponse>
        {
            protected override async void Run(Session session, Game3EnterRequest message, Action<Game3EnterResponse> reply)
            {
                Game3EnterResponse response = new Game3EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game4)]
        public class Game4EnterRequestHandler : AMRpcHandler<Game4EnterRequest, Game4EnterResponse>
        {
            protected override async void Run(Session session, Game4EnterRequest message, Action<Game4EnterResponse> reply)
            {
                Game4EnterResponse response = new Game4EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game5)]
        public class Game5EnterRequestHandler : AMRpcHandler<Game5EnterRequest, Game5EnterResponse>
        {
            protected override async void Run(Session session, Game5EnterRequest message, Action<Game5EnterResponse> reply)
            {
                Game5EnterResponse response = new Game5EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game6)]
        public class Game6EnterRequestHandler : AMRpcHandler<Game6EnterRequest, Game6EnterResponse>
        {
            protected override async void Run(Session session, Game6EnterRequest message, Action<Game6EnterResponse> reply)
            {
                Game6EnterResponse response = new Game6EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game7)]
        public class Game7EnterRequestHandler : AMRpcHandler<Game7EnterRequest, Game7EnterResponse>
        {
            protected override async void Run(Session session, Game7EnterRequest message, Action<Game7EnterResponse> reply)
            {
                Game7EnterResponse response = new Game7EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game8)]
        public class Game8EnterRequestHandler : AMRpcHandler<Game8EnterRequest, Game8EnterResponse>
        {
            protected override async void Run(Session session, Game8EnterRequest message, Action<Game8EnterResponse> reply)
            {
                Game8EnterResponse response = new Game8EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game9)]
        public class Game9EnterRequestHandler : AMRpcHandler<Game9EnterRequest, Game9EnterResponse>
        {
            protected override async void Run(Session session, Game9EnterRequest message, Action<Game9EnterResponse> reply)
            {
                Game9EnterResponse response = new Game9EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }

        [MessageHandler(AppType.Game10)]
        public class Game10EnterRequestHandler : AMRpcHandler<Game10EnterRequest, Game10EnterResponse>
        {
            protected override async void Run(Session session, Game10EnterRequest message, Action<Game10EnterResponse> reply)
            {
                Game10EnterResponse response = new Game10EnterResponse();
                try
                {
                    response.enterSucceed = await PeopleEnterRoom.Enter(session, message.Account);
                    reply(response);
                }
                catch (Exception e)
                {
                    ReplyError(response, e, reply);
                }
            }
        }



    }



}
